package com.baofu.paycore.service.facade.enums;

import com.system.commons.exception.BizServiceException;
import com.system.commons.exception.CommonErrorCode;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

/**
 * 支付工具类型
 * <p>
 *     1、余额账户
 *     2、银行卡
 *     3、积分
 *     4、代金券
 * </p>
 * User: kwl  Date: 16/4/18 ProjectName: paycore Version: 1.0
 */
@Slf4j
@Getter
@AllArgsConstructor
public enum PayToolTypeEnum {

    ACCOUNT("ACCOUNT","余额账户"),

    BANK_CARD("BANK_CARD","银行卡"),

    POINT("POINT","积分"),

    VOUCHER("VOUCHER","代金券"),

    THIRD_PAY("THIRD_PAY","第三方支付"),
    ;

    /**
     * 编码
     */
    private String code;

    /**
     * 描述
     */
    private String desc;

    /**
     * 通过枚举编码获得枚举
     *
     * @param code    枚举编码
     * @return        返回编码对应的枚举类型
     */
    public static PayToolTypeEnum explain(String code) {
        for (PayToolTypeEnum payToolTypeEnum : values()) {
            if (payToolTypeEnum.getCode().equals(code)) {
                return payToolTypeEnum;
            }
        }
        log.error("不支持支付工具类型:{}", code);
        throw new BizServiceException(CommonErrorCode.VALUE_NOT_SUPPORT, "不支持支付工具类型");
    }
}
